package byx.container.annotation.extension.impl;

import byx.container.annotation.annotation.Import;
import byx.container.annotation.annotation.Register;
import byx.container.annotation.extension.core.ClassPostProcessorContext;
import byx.container.annotation.extension.core.ClassProcessorContext;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 处理Import注解
 */
public class ImportProcessor extends BaseClassProcessor {
    public ImportProcessor(ClassScanner classScanner) {
        super(classScanner);
    }

    @Override
    public List<ClassPostProcessorContext> process(ClassProcessorContext ctx) {
        Class<?> type = ctx.getType();
        if (type.isAnnotationPresent(Register.class) && type.isAnnotationPresent(Import.class)) {
            return Arrays.stream(type.getAnnotation(Import.class).value())
                    .flatMap(t -> getTypeAndMethodContexts(t).stream())
                    .collect(Collectors.toList());
        }
        return Collections.emptyList();
    }
}
